package com.calciominoBeta.SlidingMenu;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.calciomio.app.R;
import com.calciominoBeta.Activity.Main_Activity;
import com.calciominoBeta.Fragment.ListNewsFragment;
import com.calciominoBeta.Util.MyUrl;

public class SampleListFragment extends Fragment {
	//public String[] menus =null;
	public View accuei,breves,arctiles,videos;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v= inflater.inflate(R.layout.list, null);
		accuei=v.findViewById(R.id.accuei);
		breves=v.findViewById(R.id.breves);
		arctiles=v.findViewById(R.id.arctiles);
		videos=v.findViewById(R.id.videos);
		return v;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		
		OnClickListener click =new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Fragment newContent = null;
				
				switch (v.getId()) {
				case R.id.accuei:
					newContent = new ListNewsFragment(MyUrl.HOME);
					break;
				case  R.id.breves:
					newContent = new ListNewsFragment(MyUrl.BREVES);
					break;
				case  R.id.arctiles:
					newContent = new ListNewsFragment(MyUrl.ARTICLES);
					break;
				case  R.id.videos:
					newContent = new ListNewsFragment(MyUrl.VIDEO);
					break;

				}
				if (newContent != null)
					switchFragment(newContent);
				
			}
			
			
		};
		
		accuei.setOnClickListener(click);
		breves.setOnClickListener(click);
		arctiles.setOnClickListener(click);
		videos.setOnClickListener(click);
		

	}



	private void switchFragment(Fragment fragment) {
		if (getActivity() == null)
			return;

		if (getActivity() instanceof Main_Activity) {
			Main_Activity fca = (Main_Activity) getActivity();
			fca.switchContent(fragment);
		}

	}

}
